package com.example;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.TreeSet;

public class CrossContainerIteration {
    public static void display(Iterator<String> i) {
        while (i.hasNext()) {
            System.out.print(i.next() + " ");
        }
        System.out.println();
    }

    public static void main(String[] args) {
        String[] str = { "qwer", "asdf", "zxcv", "1234" };
        ArrayList<String> arrayList = new ArrayList<>(Arrays.asList(str));
        LinkedList<String> linkedList = new LinkedList<>(Arrays.asList(str));
        HashSet<String> hashSet = new HashSet<>(Arrays.asList(str));
        TreeSet<String> treeSet = new TreeSet<>(Arrays.asList(str));
        display(arrayList.iterator());
        display(linkedList.iterator());
        display(hashSet.iterator());
        display(treeSet.iterator());
    }
}

